import 'package:number_spark_flutter/network/ns_api.dart';
import 'package:number_spark_flutter/pages/ns_mine/ns_mine_logic.dart';
import 'package:number_spark_flutter/utils/ns_toast_utils.dart';
import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';

class NSSettingUserLogic extends GetxController {
  TextEditingController nickNameController = TextEditingController();
  TextEditingController countryController = TextEditingController();
  NSMineLogic logic = Get.find();

  @override
  void onInit() {
    super.onInit();
    nickNameController.text = logic.userInfoModel.nickname ?? '';
    countryController.text = logic.userInfoModel.country ?? '';
  }

  doClickSubmit() async {
    if (nickNameController.text.isEmpty) {
      NSToast.show('Please enter nickname');
      return;
    }
    if (countryController.text.isEmpty) {
      NSToast.show('Please enter country');
      return;
    }
    Map<String, dynamic> params = {
      'nickname': nickNameController.text,
      'birthday': logic.userInfoModel.birthday,
      'country': countryController.text,
    };
    NSResponseData responseData = await NSApi.saveUserInfo.post(params);
    if (responseData.isSuccess()) {
      NSToast.show('Save Success');
      Get.back();
    }
  }
}
